package cn.cheln.support.manager.listener;


import android.app.Activity;

import java.util.HashSet;
import java.util.Set;

import cn.cheln.explorer.func.setup.PackageInstallManager;

/**
 * Created by Administrator on 14-1-4.
 */
public class HomeListener {
    public static Activity activityOnKeyHome;
    public static Set<Activity> displayingActivitySum = new HashSet<Activity>();

    public static void addInstance(Activity acty) {
        if (displayingActivitySum != null) {
            displayingActivitySum.add(acty);
        }
    }


    public static void handleResume_backResume(Activity acty) {
        if (HomeListener.activityOnKeyHome != null && HomeListener.activityOnKeyHome == acty) {
            PackageInstallManager.homeStopFlag = false;
            HomeListener.activityOnKeyHome = null;
        }
    }

    public static void removeInstance(Activity acty) {
        if (displayingActivitySum != null) {

            displayingActivitySum.remove(acty);
            if (displayingActivitySum.size() == 0) {
                activityOnKeyHome = acty;
                stopInstall();
            }
        }
    }

    public static void stopInstall() {
        if (PackageInstallManager.getInstance().isInInstall) {
            PackageInstallManager.homeStopFlag = true;
            PackageInstallManager.getInstance().endWhileAppAlive();
        }
    }

}
